# R Script Template
# Author: Cecilie Steenbuch Traberg
# Date: January 2024
# Description: Inoculation reduces susceptibility to misinformation from political ingroups

# Load relevant packages
library(devtools) #necessary for install_github function
library(jsq) #install jsq package


# Set WD
setwd("~/Dropbox/PhD Cambridge/Publications/HMR/Data")

# Import Scripts
complete_data <- read.csv("complete_data.csv")
long_data <- read.csv("long_dataperceivedgroup.csv")

# Finding 1
jmv::ANOVA(
  formula = FakePre ~ Group,
  data = complete_data,
  effectSize = "partEta",
  postHoc = ~ Group,
  postHocES = "d",
  emMeans = ~ Group,
  emmPlotData = TRUE,
  emmTables = TRUE)


#Robustness check with perceived groups
jmv::ANOVA(
  formula = FakePre ~ PerceivedGroupFake,
  data = complete_data,
  effectSize = "partEta",
  postHoc = ~ PerceivedGroupFake,
  postHocES = "d",
  emMeans = ~ PerceivedGroupFake,
  emmPlotData = TRUE,
  emmTables = TRUE)

#Robustness check with Welch's ANOVA and Games-Howell posthocs

jmv::anovaOneW(
  formula = FakePre ~ Group,
  data = complete_data,
  desc = TRUE,
  phMethod = "gamesHowell")


#Finding 2
jmv::ttestPS(
  data = complete_data,
  pairs = list(
    list(
      i1="FakePre",
      i2="FakePost")),
  meanDiff = TRUE,
  ci = TRUE,
  effectSize = TRUE,
  ciES = TRUE,
  desc = TRUE)

jmv::ANOVA(
  formula = PerceivedReliability ~ time + treatment + time:treatment,
  data = long_data,
  effectSize = "partEta",
  modelTest = TRUE,
  postHoc = ~ time:treatment + treatment + time,
  postHocES = "d",
  emMeans = ~ time:treatment + time + treatment,
  emmTables = TRUE)


# Finding 3
# BAYESIAN ANALYSIS RUN USING JAMOVI 

# Regular ANOVA

jmv::ANOVA(
  formula = PerceivedReliability ~ time + Group + time:Group,
  data = long_data,
  effectSize = c("eta", "partEta"),
  postHoc = ~ time + Group + time:Group,
  postHocES = "d",
  emMeans = ~ time + Group + time:Group,
  emmPlots = FALSE,
  emmTables = TRUE)

# ANOVA on Difference Score
jmv::ANOVA(
  formula = Dif ~ Group,
  data = complete_data,
  effectSize = "eta",
  modelTest = TRUE,
  postHoc = ~ Group,
  postHocES = "d")


# Finding 4

jmv::ANOVA(
  formula = FakePost ~ Group,
  data = complete_data,
  effectSize = "partEta",
  modelTest = TRUE,
  postHoc = ~ Group,
  postHocES = "d",
  emMeans = ~ Group,
  emmTables = TRUE)

# Finding 5

jmv::ttestPS(
  data = complete_data,
  pairs = list(
    list(
      i1="truthdiscernmentpre",
      i2="truthdiscernmentpost")),
  meanDiff = TRUE,
  effectSize = TRUE,
  desc = TRUE)

# Bayesian run using JAMOVI 

# True News Pre/Post

jmv::ttestPS(
  data = complete_data,
  pairs = list(
    list(
      i1="FakePost",
      i2="FactsPost")),
  meanDiff = TRUE,
  effectSize = TRUE,
  desc = TRUE)

